package com.ww.spark.streaming

import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.sql._
import org.apache.spark.streaming.dstream.{DStream, ReceiverInputDStream}
import org.apache.spark.streaming.{Seconds, StreamingContext}

object Streaming01_receiver01 {


  def main(args: Array[String]): Unit = {
    val sc: SparkConf = new SparkConf().setMaster("local[2]").setAppName("streaming01")
    val ssc = new StreamingContext(sc, Seconds(5))
    val receiverStream: ReceiverInputDStream[String] = ssc.socketTextStream("192.168.101.121", 8888)
    val res: DStream[(String, Int)] = receiverStream.flatMap(_.split(" ")).map((_, 1)).reduceByKey(_ + _)
    res.print()


    ssc.start()
    ssc.awaitTermination()
    println("\n =====================================================================================================================")


  }
}
